package com.pni.game.cards.deck;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Stack;

import com.pni.game.cards.Card;
import com.pni.game.cards.CardHolder;


/**
 * This class is exactly what you expect, a data structure representing a deck of cards
 * @author Phil, Neil
 *
 */
public abstract class Deck implements DeckInterface {
	
	/**
	 * Remove a card from the deck and return it, if there is no more cards left to draw then return null
	 * @return
	 */
	public Card drawCard(){
		Card card = null;
		if(isEmpty()){
			card = null;
		}else{
			card = takeCard();
		}
		return card;
	}
	
	/**
	 * Draws a certain number of cards from the deck.  If the number of cards specified is greater then the current deck
	 * size it will return all of the remaining cards in the deck (e.g. If 5 cards are requested and the deck only
	 * contained 4 cards, a <code>Collection</code> of 4 cards is returned. If no cards are left, null is returned.
	 * 
	 * @param number the number of cards to be drawn from the deck.
	 * @return a <code>Collection</code> of cards drawn from the deck.
	 */
	public Collection<Card> drawCards(int number) {
		
		if (number > numberOfCards()) {
			number = numberOfCards();
		}

		if (number <= 0) {
			return null;
		}
		
		ArrayList<Card> drawnCards = new ArrayList<Card>();
		for(int cardNumber = 0; cardNumber < number; cardNumber++){
			Card card = drawCard();
			drawnCards.add(card);
		}
		
		return drawnCards;
	}
	
	/**
	 * 	Places a card on the top of the deck.
	 * 
	 * @param card - Card to place on top of the deck.
	 */
	public void placeCardOnDeck(Card card){
		addCard(card);
	}
}
